package rpc

import (
	"gitee.com/go-course/go8/projects/devcloud/mcenter/client/rpc"
	"github.com/caarlos0/env/v6"
)

var (
	client *ClientSet
)

// C Global
func C() *ClientSet {
	return client
}

// LoadClientFromEnv 从环境变量中生成客户端实例
func LoadClientFromEnv() error {
	cfg := rpc.NewConfig("127.0.0.1:19010", "", "")
	if err := env.Parse(cfg); err != nil {
		return err
	}
	// 加载全局客户端单例
	c, err := NewClient(cfg)
	if err != nil {
		return err
	}
	client = c
	return nil
}
